﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using System.Xml;

namespace CrazyWorship1
{
    [XmlRoot("ClientListRoot")]
    public class ClientList : ObservableCollection<Client>, IXmlSerializable
    {
        protected override void RemoveItem(int index)
        {
            base.RemoveItem(index);

        }

        public ClientList()
        {
            _screenInfoList = new ScreenInfoList();
            _screenList = new ScreenList();
        }


        public ScreenInfoList ScreenInfoList
        {
            get
            {

                return _screenInfoList;
            }
        }
        ScreenInfoList _screenInfoList;
        public ScreenList ScreenList
        {
            get
            {
                return _screenList;
            }
        }
        ScreenList _screenList;







        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.ReadStartElement("ClientListRoot");
            reader.ReadStartElement("ClientList");
            if (reader.NodeType != XmlNodeType.EndElement)
            {
                reader.ReadStartElement("ClientListGroup");
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    Client c = new Client(this);
                    c.ReadXml(reader);
                    this.Add(c);
                }
                reader.ReadEndElement();
            }
           // _screenInfoList.ReadXml(reader);
            reader.ReadEndElement();

           // reader.ReadEndElement();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteStartElement("ClientList");
            writer.WriteStartElement("ClientListGroup");
            foreach (Client c in this)
            {
                ((IXmlSerializable)c).WriteXml(writer);
            }
            writer.WriteEndElement();
         //   ((IXmlSerializable)_screenInfoList).WriteXml(writer);
         //   ((IXmlSerializable)_screenList).WriteXml(writer);
            writer.WriteEndElement();

        }

        #endregion
    }
}
